package simulation;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

import java.util.EnumMap;

public class Main extends Application {
    private static StudentPane studentPane;

    @Override
    public void start(Stage primaryStage) throws Exception{
        BorderPane root = FXMLLoader.load(getClass().getResource("../gui/gui.fxml"));
        AnchorPane labels = FXMLLoader.load(getClass().getResource("../gui/labels.fxml"));

        primaryStage.setTitle("新冠病毒传播模拟");
        primaryStage.setScene(new Scene(root, 1300, 820));
        primaryStage.show();
        primaryStage.setResizable(false);

        // 初始化地图和时间表全局常量
        Map.initMap();
        Timetable.initTimetables();
        studentPane = new StudentPane(1000);
        // 强制类型转换后叠加！
        AnchorPane p = (AnchorPane) root.getCenter();
        p.getChildren().add(labels);
        p.getChildren().add(studentPane);
        //((AnchorPane)root.getCenter()).getChildren().add(studentPane);
        // debug
        p.setOnMouseClicked(e ->
        {
          //  studentPane.pauseTimerTask();
            System.out.println(e.getX() + ", " + e.getY());
        });

        // 关闭窗口后结束程序
        primaryStage.setOnCloseRequest(e -> {
            Platform.exit();
            System.exit(0);
        });
    }

    public static void setNum(int num) {
        studentPane.setNum(num);
    }

    public static void main(String[] args) {
        launch(args);
    }

    public static void step() {
        studentPane.repaint();
    }

    public static EnumMap<State, Integer> getCurrPop() {
        return studentPane.getCurrPop();
    }
}
